package krow.dev.contest.view;

import java.util.ArrayList;
import java.util.List;

import krow.dev.contest.R;
import krow.dev.contest.model.SubcategoryItem;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;



public class SubcategoryListAdapter extends BaseAdapter {

	private List<SubcategoryItem> mSubcategoryItemList;

	private LayoutInflater mLayoutInflater;
	
	public SubcategoryListAdapter(Context context) {
	
		mSubcategoryItemList = new ArrayList<SubcategoryItem>();
		
		mLayoutInflater = LayoutInflater.from(context);
	}

	public void setSubcategoryItemList(List<SubcategoryItem> subcategoryItemList){
		
		mSubcategoryItemList.clear();
		mSubcategoryItemList.addAll(subcategoryItemList);
	}
	
	@Override
	public int getCount() {

		return mSubcategoryItemList.size();
	}

	@Override
	public Object getItem(int position) {

		return mSubcategoryItemList.get(position);
	}

	@Override
	public long getItemId(int position) {

		return position;
	}

	
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		
		SubcategoryItem subcategoryItem = mSubcategoryItemList.get(position);
		
		View view = mLayoutInflater.inflate(R.layout.item_menu, null);
		view.setTag(subcategoryItem);
		
		View iconView = view.findViewById(R.id.view_icon);
		
		TextView nameView = (TextView) view.findViewById(R.id.text_name);
		nameView.setText(subcategoryItem.getName());
		
		//TextView countView = (TextView) view.findViewById(R.id.text_count);
		//countView.setText(String.valueOf(subcategoryItem.getCount()));
		
		
		return view;
	}	
	
}
